package binary_evolution;

import misc.not_Legal_Exception;
import evolution_superclasses.Genotype;
import evolution_superclasses.Phenotype;

public class Binary_Genotype extends Genotype {
	protected boolean[] _binaryArray;

	public Binary_Genotype(int size) {
		super(size);
	}

	public boolean[] get_binaryArray() {
		return _binaryArray;
	}

	public void set_binaryArray(boolean[] binaryArray) {
		_binaryArray = binaryArray;
	}
	
	public void editBinaryArray(int i, boolean value){
		_binaryArray[i] = value;
	}

	@Override
	public Phenotype generatePhenotype(){
		set_phenotype(new Binary_Phenotype(this));
		return get_phenotype();
	}

	@Override
	public String toString() {
		String s = "";
		for(boolean b :get_binaryArray()){
			s += b?'1':'0';
		}
		return s;
	}

	@Override
	public void createGenotype(int size) throws not_Legal_Exception{
		_binaryArray = new boolean[size];
		
		for (int i = 0; i < size; i++)
			_binaryArray[i] = _rand.nextBoolean();
	}

}
